<?php

include 'db-control/dbOrganization.php';
$result = dbOrganization::getAllOrganizations();

if (isset($_REQUEST['cityChange'])) {
   $_SESSION['selectedCity'] = $_REQUEST['cityChange'];
}
$city = isset($_SESSION['selectedCity']) ? $_SESSION['selectedCity'] : null;

drawCityDropdown($city);

$category = $_SESSION['category'];
if ($city == null) {
   $query = "SELECT o.city, o.stateName, o.organizationName, io.* FROM opportunity io, organization o WHERE io.organizationID = o.OrganizationID AND io.categories LIKE '%$category%' ORDER BY o.city";
} else {
   $query = "SELECT o.city, o.stateName, o.organizationName, io.* FROM opportunity io, organization o WHERE io.organizationID = o.OrganizationID AND o.city='$city' AND io.categories LIKE '%$category%' ORDER BY io.dateAdded DESC";
}

$result = mysql_query($query);
if (!$result)die("Could not complete query...");
$numRows = mysql_num_rows($result);
echo "<table width='100%' cellspacing=0><tr><td width='10%'></td><td width='15%'><b>Location</b></td><td width='15%'><b>Position</b></td><td width='15%'><b>Company</b></td><td width='10%'><b>Positions Available</b></td><td><b>Pay Rate</b></td><td><b>Semester</b></td><td width='10%'><b>Date Added</b></td></tr>";
echo "<tr><td colspan=8><hr /></td></tr>";
for ($x = 0; $x < $numRows; $x++) {
   $row = mysql_fetch_assoc($result);
   echo (($x % 2) == 0) ? "<tr>" : "<tr bgcolor='#FBFBFB'>";
   $id = $row['opportunityID'];
   $city = $row['city'];
   $state = $row['stateName'];
   $title = $row['title'];
   $name = $row['organizationName'];
   $numPositions = $row['numPositionsAvailable'];
   $payRate = $row['payRate'];
   $semester = $row['semester'];
   $date = $row['dateAdded'];
   $date = substr($date, 0, 10);
   echo "<td align='center' valign='middle'><br /><form action='index.php' method='get'><input type='hidden' name='internship_id' value='$id'><input type='submit' value='View' class='submit' name='view_info' /></form></td>";
   echo "<td>$city, " . strtoupper($state) . "</td>";
   echo "<td>$title</td>";
   echo "<td>$name</td>";
   echo "<td>$numPositions</td>";
   echo "<td>$payRate</td>";
   echo "<td>$semester</td>";
   echo "<td>$date</td>";
   echo "</tr>";
}
echo "</table>";



?>
